<?php
/* @var $this UserController */
/* @var $model User */
/* @var $form CActiveForm */
?>

<?php
/* @var $this SiteController */
$this->pageTitle=Yii::app()->name;
?>
<style type="text/css">
	.container {
		min-width: 1005px;
	}
	section{
		width: 100%;
		/*height: 524px;*/
		padding-top: 55px;
		background-image: url('themes/fly_high/assets/img/web.png');
		background-position: top left;
		background-repeat: no-repeat;
		display: table;
	}
	#loading{
        width: 64px;
        height: 64px;
        background-image: url("<?php echo Yii::app()->request->baseUrl; ?>/themes/fly_high/assets/img/loading.gif");
        position: fixed;
        top: 50%;
        left: 50%;
        display: none;
    }
	#registerForm{
		width: 341px;
		/*height: 411px;*/
		display: table;
		background: #5d5d5d;
		margin-left: 51%;
		opacity: 0.9;
		padding: 20px 30px;
	}
	#registerForm>header{
		color: #c0c0c0;
		font-size: 30px;
	}
	#submit input{
		height: 2.5em;
    	width: 100%;
		background: none repeat scroll 0 0 #666666 !important;
	    border: 1px solid #454545 !important;
	    color: #c0c0c0 !important;
	}
	.row>label{
		color: #c0c0c0 !important;
		font-size: 1em !important;
	}
	.row>input,.row>select {
		height: 2em;
    	width: 100%;
	}
	/*label[for="sex"]{
		width: 100%;
	}*/
</style>

<script>
function sendAjax(){
	var data=$("#user-register-form").serialize();
	data += '&yt0=Đăng ký';

	$('#btnRegister').attr("disabled", true);
	$('#loading').fadeIn();

	$.ajax({
			type: 'POST',
		url: '<?php echo Yii::app()->createAbsoluteUrl("User"); ?>',
			data:data,
		success:function(data){
			$('#loading').fadeOut();
			$('#btnRegister').attr("disabled", false);
			if(data != 'Đăng nhập thành công')
				alert(data);
			else
				alert('Đăng ký thành công');
				window.location.href = "<?php Yii::app()->user->returnUrl?>";
	  	},
	dataType:'html'
	});
};
</script>
<div id="loading"></div>
<div id="registerForm">
	<header>ĐĂNG KÝ</header>
	<fieldset>
		<div class="form">
			<?php $form=$this->beginWidget('CActiveForm', array(
				'id'=>'user-register-form',
				// Please note: When you enable ajax validation, make sure the corresponding
				// controller action is handling ajax validation correctly.
				// See class documentation of CActiveForm for details on this,
				// you need to use the performAjaxValidation()-method described there.
				'action' => Yii::app()->request->baseUrl. '/User/',  //<- your form action here
				'enableAjaxValidation'=>false,
				'enableClientValidation'=>true,
				'clientOptions'=>array(
					'validateOnSubmit'=>true,
					'afterValidate'=>'js:function(form, data, hasError) {
			            if(jQuery.isEmptyObject(data)) {
			            	sendAjax();
			            }
			            return false;
			        }'
				),
			)); ?>
				<?php echo $form->errorSummary($model); ?>

		        <div class="row">
					<?php echo $form->labelEx($model,'name'); ?>
					<?php echo $form->textField($model,'name'); ?>
					<?php echo $form->error($model,'name'); ?>
				</div>

				<div class="row">
					<?php echo $form->labelEx($model,'email'); ?>
					<?php echo $form->emailField($model,'email'); ?>
					<?php echo $form->error($model,'email'); ?>
				</div>

				<div class="row">
					<?php echo $form->labelEx($model,'password'); ?>
					<?php echo $form->passwordField($model,'password'); ?>
					<?php echo $form->error($model,'password'); ?>
				</div>

				<div class="row">
					<?php echo $form->labelEx($model,'birthday'); ?>
					<?php echo $form->dateField($model,'birthday'); ?>
					<?php echo $form->error($model,'birthday'); ?>
				</div>

				<div class="row">
					<?php echo $form->labelEx($model,'sex'); ?>
					<?php echo $form->dropDownList($model,'sex',array('1'=>'Nam','0'=>'Nữ')); ?>
					<?php echo $form->error($model,'sex'); ?>
				</div>

				<?php if($model->scenario == 'withCaptcha' && CCaptcha::checkRequirements()): ?>
				<div class="row">
					<?php echo $form->labelEx($model,'verifyCode'); ?>
					<?php $this->widget('CCaptcha'); ?>
					<?php echo $form->textField($model,'verifyCode'); ?>
					<?php echo $form->error($model,'verifyCode'); ?>
				</div>
				<?php endif; ?>

				<div class="row buttons" id="submit">
					<?php echo CHtml::submitButton('Đăng ký',array('id'=>'btnRegister')); ?>
				</div>

			<?php $this->endWidget(); ?>

			</div><!-- form -->
    </fieldset>
</div>
